public class GetDis {
    public int getDis (int[] A, int n) {
        // write code here
        int ret = 0;
        int min = 0x3f3f3f3f;
        int max = -0x3f3f3f3f;
        for (int num : A) {
            if (num < min) {
                min = num;
                max = num;
            } else if (num > max) {
                max = num;
                ret = Math.max(ret, max-min);
            }
        }
        return ret;
    }
}
